import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"),
    },
  },
  server: {
    port: 5173,
    open: true,
    cors: true,
    hmr: {
      overlay: true, // 启用错误覆盖层
      clientPort: 5173, // 确保客户端端口正确
      host: "localhost", // 使用localhost而不是IP
    },
    watch: {
      usePolling: true, // 在某些系统上可能需要轮询来检测文件更改
      interval: 100, // 轮询间隔
    },
  },
  build: {
    outDir: "dist",
    assetsDir: "assets",
    sourcemap: true, // 开发时启用sourcemap
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `
          $primary-color: #409EFF;
          $success-color: #67C23A;
          $warning-color: #E6A23C;
          $danger-color: #F56C6C;
          $text-primary: #303133;
          $text-regular: #606266;
          $text-secondary: #909399;
          $border-color: #e4e7ed;
          $bg-color: #f5f7fa;
        `,
      },
    },
    devSourcemap: true, // 启用CSS sourcemap
  },
  optimizeDeps: {
    include: [
      "vue",
      "vue-router",
      "pinia",
      "axios",
      "element-plus",
      "@element-plus/icons-vue",
    ],
  },
});
